#include <pthread.h>
#include <iostream>
#include <unistd.h>

void* threadFunc(void* arg) {
    while (true) {
        std::cout << "子线程正在运行...\n";
        sleep(1);
    }
    return nullptr;
}

int main() {
    pthread_t thread;

    pthread_create(&thread, nullptr, threadFunc, nullptr);
    sleep(3);

    pthread_cancel(thread); // 发送取消请求
    pthread_join(thread, nullptr);

    std::cout << "子线程已被取消.\n";
    return 0;
}
